var e,t,n;!function(e){e.CSS="css",e.ARIA="aria",e.Text="text",e.XPath="xpath",e.Pierce="pierce"}(e=e||(e={})),function(e){e.Change="change",e.Click="click",e.Close="close",e.CustomStep="customStep",e.DoubleClick="doubleClick",e.EmulateNetworkConditions="emulateNetworkConditions",e.Hover="hover",e.KeyDown="keyDown",e.KeyUp="keyUp",e.Navigate="navigate",e.Scroll="scroll",e.SetViewport="setViewport",e.WaitForElement="waitForElement",e.WaitForExpression="waitForExpression"}(t=t||(t={})),function(e){e.Navigation="navigation"}(n=n||(n={}));var r=Object.freeze({__proto__:null,get SelectorType(){return e},get StepType(){return t},get AssertedEventType(){return n}});function a(e){throw new Error(`Unknown step type: ${e.type}`)}const i=new Set(["textarea","text","url","tel","search","password","number","email"]),o=new Set(["mouse","pen","touch"]),s=new Map([["primary","left"],["auxiliary","middle"],["secondary","right"],["back","back"],["forward","forward"]]);function l(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))return!1;return void 0!==e[t]}function c(e){return"object"==typeof e&&null!==e}function u(e){return"string"==typeof e}function p(e){return"number"==typeof e}function f(e){return Array.isArray(e)}function w(e){if(l(e,"target")&&u(e.target))return e.target}function d(e){if(l(e,"frame")){if(f(t=e.frame)&&t.every((e=>Number.isInteger(e))))return e.frame;throw new Error("Step `frame` is not an integer array")}var t}function h(e,t){if(l(e,t)){const n=e[t];if(p(n))return n}throw new Error(`Step.${t} is not a number`)}function m(e,t){if(l(e,t)){const n=e[t];if("boolean"==typeof n)return n}throw new Error(`Step.${t} is not a boolean`)}function y(e,t){if(l(e,t))return h(e,t)}function g(e,t){if(l(e,t))return b(e,t)}function v(e,t){if(l(e,t))return m(e,t)}function b(e,t){if(l(e,t)){const n=e[t];if(u(n))return n}throw new Error(`Step.${t} is not a string`)}function E(e){if(!l(e,"selectors"))throw new Error("Step does not have required selectors");if(!f(e.selectors))throw new Error("Step selectors are not an array");if(0===e.selectors.length)throw new Error("Step does not have required selectors");return e.selectors.map((e=>{if(!u(e)&&!f(e))throw new Error("Selector is not an array or string");return f(e)?e.map((e=>{if(!u(e))throw new Error("Selector element is not a string");return e})):e}))}function S(e){if(l(e,"selectors"))return E(e)}function L(e){if(!c(e))throw new Error("Asserted event is not an object");if(!l(e,"type"))throw new Error("Asserted event is missing type");if(e.type===n.Navigation)return{type:n.Navigation,url:g(e,"url"),title:g(e,"title")};throw new Error("Unknown assertedEvent type")}function k(e){if(f(e))return e.map(L)}function F(e,t){if(l(t,"timeout")&&p(t.timeout)&&!P(t.timeout))throw new Error(j);return{type:e,assertedEvents:l(t,"assertedEvents")?k(t.assertedEvents):void 0,timeout:l(t,"timeout")&&p(t.timeout)?t.timeout:void 0}}function A(e,t){return{...F(e,t),target:w(t)}}function C(e,t){return{...A(e,t),frame:d(t)}}function $(e,t){return{...C(e,t),selectors:E(t)}}function x(e){const t={offsetX:h(e,"offsetX"),offsetY:h(e,"offsetY"),duration:y(e,"duration")},n=g(e,"deviceType");if(n){if("string"!=typeof(r=n)||!o.has(r))throw new Error(`'deviceType' for click steps must be one of the following: ${[...o].join(", ")}`);t.deviceType=n}var r;const a=g(e,"button");if(a){if(!function(e){return"string"==typeof e&&s.has(e)}(a))throw new Error(`'button' for click steps must be one of the following: ${[...s.keys()].join(", ")}`);t.button=a}return t}function T(e,n){if(!c(e))throw new Error(n?`Step ${n} is not an object`:"Step is not an object");if(!l(e,"type"))throw new Error(n?`Step ${n} does not have a type`:"Step does not have a type");if(!u(e.type))throw new Error(n?`Type of the step ${n} is not a string`:"Type of the step is not a string");switch(e.type){case t.Click:return function(e){return{...$(t.Click,e),...x(e),type:t.Click}}(e);case t.DoubleClick:return function(e){return{...$(t.DoubleClick,e),...x(e),type:t.DoubleClick}}(e);case t.Hover:return function(e){return{...$(t.Hover,e),type:t.Hover}}(e);case t.Change:return function(e){return{...$(t.Change,e),type:t.Change,value:b(e,"value")}}(e);case t.KeyDown:return function(e){return{...A(t.KeyDown,e),type:t.KeyDown,key:b(e,"key")}}(e);case t.KeyUp:return function(e){return{...A(t.KeyUp,e),type:t.KeyUp,key:b(e,"key")}}(e);case t.EmulateNetworkConditions:return function(e){return{...A(t.EmulateNetworkConditions,e),type:t.EmulateNetworkConditions,download:h(e,"download"),upload:h(e,"upload"),latency:h(e,"latency")}}(e);case t.Close:return function(e){return{...A(t.Close,e),type:t.Close}}(e);case t.SetViewport:return function(e){return{...A(t.SetViewport,e),type:t.SetViewport,width:h(e,"width"),height:h(e,"height"),deviceScaleFactor:h(e,"deviceScaleFactor"),isMobile:m(e,"isMobile"),hasTouch:m(e,"hasTouch"),isLandscape:m(e,"isLandscape")}}(e);case t.Scroll:return function(e){return{...C(t.Scroll,e),type:t.Scroll,x:y(e,"x"),y:y(e,"y"),selectors:S(e)}}(e);case t.Navigate:return function(e){return{...A(t.Navigate,e),type:t.Navigate,target:w(e),url:b(e,"url")}}(e);case t.CustomStep:return function(e){if(!l(e,"name"))throw new Error("customStep is missing name");if(!u(e.name))throw new Error("customStep's name is not a string");return{...C(t.CustomStep,e),type:t.CustomStep,name:e.name,parameters:l(e,"parameters")?e.parameters:void 0}}(e);case t.WaitForElement:return function(e){const n=g(e,"operator");if(n&&">="!==n&&"=="!==n&&"<="!==n)throw new Error("WaitForElement step's operator is not one of '>=','==','<='");if(l(e,"attributes")&&(!c(e.attributes)||Object.values(e.attributes).some((e=>"string"!=typeof e))))throw new Error("WaitForElement step's attribute is not a dictionary of strings");if(l(e,"properties")&&!c(e.properties))throw new Error("WaitForElement step's attribute is not an object");return{...$(t.WaitForElement,e),type:t.WaitForElement,operator:n,count:y(e,"count"),visible:v(e,"visible"),attributes:l(e,"attributes")?e.attributes:void 0,properties:l(e,"properties")?e.properties:void 0}}(e);case t.WaitForExpression:return function(e){if(!l(e,"expression"))throw new Error("waitForExpression step is missing `expression`");return{...C(t.WaitForExpression,e),type:t.WaitForExpression,expression:b(e,"expression")}}(e);default:throw new Error(`Step type ${e.type} is not supported`)}}function I(e){const t=[];if(!f(e))throw new Error("Recording `steps` is not an array");for(const[n,r]of e.entries())t.push(T(r,n));return t}const N=1,V=3e4,j="Timeout is not between 1 and 30000 milliseconds";function P(e){return e>=1&&e<=3e4}function W(e){if(!c(e))throw new Error("Recording is not an object");if(!l(e,"title"))throw new Error("Recording is missing `title`");if(!u(e.title))throw new Error("Recording `title` is not a string");if(l(e,"timeout")&&!p(e.timeout))throw new Error("Recording `timeout` is not a number");if(!l(e,"steps"))throw new Error("Recording is missing `steps`");if(l(e,"timeout")&&p(e.timeout)&&!P(e.timeout))throw new Error(j);return t={title:e.title,timeout:l(e,"timeout")&&p(e.timeout)?e.timeout:void 0,selectorAttribute:l(e,"selectorAttribute")&&u(e.selectorAttribute)?e.selectorAttribute:void 0,steps:I(e.steps)},JSON.parse(JSON.stringify(t));var t}function O(t){for(const n of Object.values(e))if(t.startsWith(`${n}/`))return n;return e.CSS}class R{async beforeAllSteps(e,t){}async afterAllSteps(e,t){}async beforeEachStep(e,t,n){}async stringifyStep(e,t,n){}async afterEachStep(e,t,n){}}class M extends R{async beforeAllSteps(e,t){const n={...t,steps:void 0},r=JSON.stringify(n,null,e.getIndent()).split("\n");r.pop(),r[r.length-1]+=",",r.push(e.getIndent()+'"steps": ['),e.appendLine(r.join("\n")).startBlock().startBlock()}async afterAllSteps(e){e.endBlock().endBlock().appendLine(e.getIndent()+"]").appendLine("}")}async stringifyStep(e,t,n){const r=JSON.stringify(t,null,e.getIndent());if(!n)return void e.appendLine(r);const a=n.steps.lastIndexOf(t)===n.steps.length-1?"":",";e.appendLine(r+a)}}function B(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function D(e,t,n,r,a){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!a)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!a:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?a.call(e,n):a?a.value=n:t.set(e,n),n}var H,K,U;class q{constructor(e){H.set(this,void 0),K.set(this,0),U.set(this,[]),D(this,H,e,"f")}appendLine(e){const t=e.split("\n").map((e=>e?B(this,H,"f").repeat(B(this,K,"f"))+e.trimEnd():""));return B(this,U,"f").push(...t),this}startBlock(){var e;return D(this,K,(e=B(this,K,"f"),++e),"f"),this}endBlock(){var e;return D(this,K,(e=B(this,K,"f"),--e),"f"),this}toString(){return B(this,U,"f").join("\n")+"\n"}getIndent(){return B(this,H,"f")}getSize(){return B(this,U,"f").length}}function X(e,t){const n=[];return J(e,n,1,t),n.join("")}function J(e,t=[],n=1,r="  "){switch(typeof e){case"bigint":case"symbol":case"function":case"undefined":throw new Error("Invalid JSON");case"number":case"boolean":t.push(String(e));break;case"string":t.push(z(e));break;case"object":if(null===e)t.push("null");else if(Array.isArray(e)){t.push("[\n");for(let a=0;a<e.length;a++)t.push(r.repeat(n)),J(e[a],t,n+1,r),a!==e.length-1&&t.push(","),t.push("\n");t.push(r.repeat(n-1)+"]")}else{t.push("{\n");const a=Object.keys(e);for(let i=0;i<a.length;i++){const o=a[i],s=e[o];void 0!==s&&(t.push(r.repeat(n)),t.push(o),t.push(": "),J(s,t,n+1,r),i!==a.length-1&&t.push(","),t.push("\n"))}t.push(r.repeat(n-1)+"}")}break;default:throw new Error("Unknown object type")}return t}H=new WeakMap,K=new WeakMap,U=new WeakMap;const Y=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),_=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),z=e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=(e,t,n,r)=>{if(n){if(_.has(n))return _.get(n);return"\\x"+Y(n.charCodeAt(0),2)}if(r){return"\\u"+Y(r.charCodeAt(0),4)}return t?_.get(t)||"":e};let a="",i="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(i="'",a=e.replace(n,r)):(i="`",a=e.replace(t,r)):(i='"',a=e.replace(t,r)):(i="'",a=e.replace(t,r)),`${i}${a}${i}`};var G,Q,Z,ee,te,ne,re,ae,ie,oe,se,le,ce,ue,pe,fe,we,de,he;class me extends R{constructor(){super(...arguments),G.add(this)}async beforeAllSteps(e,t){e.appendLine("const puppeteer = require('puppeteer'); // v13.0.0 or later"),e.appendLine(""),e.appendLine("(async () => {").startBlock(),e.appendLine("const browser = await puppeteer.launch();"),e.appendLine("const page = await browser.newPage();"),e.appendLine(`const timeout = ${t.timeout||ye};`),e.appendLine("page.setDefaultTimeout(timeout);"),e.appendLine("")}async afterAllSteps(e,t){e.appendLine(""),e.appendLine("await browser.close();"),e.appendLine("");for(const t of ge.split("\n"))e.appendLine(t);e.endBlock().appendLine("})().catch(err => {").startBlock(),e.appendLine("console.error(err);"),e.appendLine("process.exit(1);"),e.endBlock().appendLine("});")}async stringifyStep(e,t,r){if(e.appendLine("{").startBlock(),void 0!==t.timeout&&e.appendLine(`const timeout = ${t.timeout};`),B(this,G,"m",ee).call(this,e,t),t.assertedEvents){e.appendLine("const promises = [];");for(const r of t.assertedEvents){if(r.type!==n.Navigation)throw new Error(`Event type ${r.type} is not supported`);e.appendLine(`promises.push(${"frame"in t&&t.frame?"frame":"targetPage"}.waitForNavigation());`)}}B(this,G,"m",fe).call(this,e,t),t.assertedEvents&&e.appendLine("await Promise.all(promises);"),e.endBlock().appendLine("}")}}G=new WeakSet,Q=function(e,t){"main"===t?e.appendLine("const targetPage = page;"):(e.appendLine(`const target = await browser.waitForTarget(t => t.url() === ${X(t,e.getIndent())}, { timeout });`),e.appendLine("const targetPage = await target.page();"),e.appendLine("targetPage.setDefaultTimeout(timeout);"))},Z=function(e,t){e.appendLine("let frame = targetPage.mainFrame();");for(const n of t)e.appendLine(`frame = frame.childFrames()[${n}];`)},ee=function(e,t){B(this,G,"m",Q).call(this,e,t.target||"main"),t.frame&&B(this,G,"m",Z).call(this,e,t.frame)},te=function(e,t){e.appendLine(`await scrollIntoViewIfNeeded(${X(t.selectors,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`),e.appendLine(`const element = await waitForSelectors(${X(t.selectors,e.getIndent())}, ${t.frame?"frame":"targetPage"}, { timeout, visible: true });`)},ne=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("await element.click({"),t.duration&&e.appendLine(`  delay: ${t.duration},`),t.button&&e.appendLine(`  button: '${s.get(t.button)}',`),e.appendLine("  offset: {"),e.appendLine(`    x: ${t.offsetX},`),e.appendLine(`    y: ${t.offsetY},`),e.appendLine("  },"),e.appendLine("});")},re=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("await element.click({"),t.button&&e.appendLine(`  button: '${s.get(t.button)}',`),e.appendLine("  offset: {"),e.appendLine(`    x: ${t.offsetX},`),e.appendLine(`    y: ${t.offsetY},`),e.appendLine("  },"),e.appendLine("});"),e.appendLine("await element.click({"),e.appendLine("  clickCount: 2,"),t.duration&&e.appendLine(`  delay: ${t.duration},`),t.button&&e.appendLine(`  button: '${s.get(t.button)}',`),e.appendLine("  offset: {"),e.appendLine(`    x: ${t.offsetX},`),e.appendLine(`    y: ${t.offsetY},`),e.appendLine("  },"),e.appendLine("});")},ae=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("await element.hover();")},ie=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("const inputType = await element.evaluate(el => el.type);"),e.appendLine("if (inputType === 'select-one') {"),e.appendLine(`  await changeSelectElement(element, ${X(t.value,e.getIndent())})`),e.appendLine(`} else if (${X(Array.from(i),e.getIndent())}.includes(inputType)) {`),e.appendLine(`  await typeIntoElement(element, ${X(t.value,e.getIndent())});`),e.appendLine("} else {"),e.appendLine(`  await changeElementValue(element, ${X(t.value,e.getIndent())});`),e.appendLine("}")},oe=function(e,t){e.appendLine("await targetPage.emulateNetworkConditions({"),e.appendLine(`  offline: ${!t.download&&!t.upload},`),e.appendLine(`  downloadThroughput: ${t.download},`),e.appendLine(`  uploadThroughput: ${t.upload},`),e.appendLine(`  latency: ${t.latency},`),e.appendLine("});")},se=function(e,t){e.appendLine(`await targetPage.keyboard.down(${X(t.key,e.getIndent())});`)},le=function(e,t){e.appendLine(`await targetPage.keyboard.up(${X(t.key,e.getIndent())});`)},ce=function(e,t){e.appendLine("await targetPage.close()")},ue=function(e,t){e.appendLine(`await targetPage.setViewport(${X({width:t.width,height:t.height},e.getIndent())})`)},pe=function(e,t){"selectors"in t?(B(this,G,"m",te).call(this,e,t),e.appendLine(`await element.evaluate((el, x, y) => { el.scrollTop = y; el.scrollLeft = x; }, ${t.x}, ${t.y});`)):e.appendLine(`await targetPage.evaluate((x, y) => { window.scroll(x, y); }, ${t.x}, ${t.y})`)},fe=function(e,n){switch(n.type){case t.Click:return B(this,G,"m",ne).call(this,e,n);case t.DoubleClick:return B(this,G,"m",re).call(this,e,n);case t.Hover:return B(this,G,"m",ae).call(this,e,n);case t.Change:return B(this,G,"m",ie).call(this,e,n);case t.EmulateNetworkConditions:return B(this,G,"m",oe).call(this,e,n);case t.KeyDown:return B(this,G,"m",se).call(this,e,n);case t.KeyUp:return B(this,G,"m",le).call(this,e,n);case t.Close:return B(this,G,"m",ce).call(this,e,n);case t.SetViewport:return B(this,G,"m",ue).call(this,e,n);case t.Scroll:return B(this,G,"m",pe).call(this,e,n);case t.Navigate:return B(this,G,"m",we).call(this,e,n);case t.WaitForElement:return B(this,G,"m",he).call(this,e,n);case t.WaitForExpression:return B(this,G,"m",de).call(this,e,n);case t.CustomStep:return;default:return a(n)}},we=function(e,t){e.appendLine(`await targetPage.goto(${X(t.url,e.getIndent())});`)},de=function(e,t){e.appendLine(`await ${t.frame?"frame":"targetPage"}.waitForFunction(${X(t.expression,e.getIndent())}, { timeout });`)},he=function(e,t){e.appendLine(`await waitForElement(${X(t,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`)};const ye=5e3,ge="async function waitForSelectors(selectors, frame, options) {\n  for (const selector of selectors) {\n    try {\n      return await waitForSelector(selector, frame, options);\n    } catch (err) {\n      console.error(err);\n    }\n  }\n  throw new Error('Could not find element for selectors: ' + JSON.stringify(selectors));\n}\n\nasync function scrollIntoViewIfNeeded(selectors, frame, timeout) {\n  const element = await waitForSelectors(selectors, frame, { visible: false, timeout });\n  if (!element) {\n    throw new Error(\n      'The element could not be found.'\n    );\n  }\n  await waitForConnected(element, timeout);\n  const isInViewport = await element.isIntersectingViewport({threshold: 0});\n  if (isInViewport) {\n    return;\n  }\n  await element.evaluate(element => {\n    element.scrollIntoView({\n      block: 'center',\n      inline: 'center',\n      behavior: 'auto',\n    });\n  });\n  await waitForInViewport(element, timeout);\n}\n\nasync function waitForConnected(element, timeout) {\n  await waitForFunction(async () => {\n    return await element.getProperty('isConnected');\n  }, timeout);\n}\n\nasync function waitForInViewport(element, timeout) {\n  await waitForFunction(async () => {\n    return await element.isIntersectingViewport({threshold: 0});\n  }, timeout);\n}\n\nasync function waitForSelector(selector, frame, options) {\n  if (!Array.isArray(selector)) {\n    selector = [selector];\n  }\n  if (!selector.length) {\n    throw new Error('Empty selector provided to waitForSelector');\n  }\n  let element = null;\n  for (let i = 0; i < selector.length; i++) {\n    const part = selector[i];\n    if (element) {\n      element = await element.waitForSelector(part, options);\n    } else {\n      element = await frame.waitForSelector(part, options);\n    }\n    if (!element) {\n      throw new Error('Could not find element: ' + selector.join('>>'));\n    }\n    if (i < selector.length - 1) {\n      element = (await element.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n    }\n  }\n  if (!element) {\n    throw new Error('Could not find element: ' + selector.join('|'));\n  }\n  return element;\n}\n\nasync function waitForElement(step, frame, timeout) {\n  const {\n    count = 1,\n    operator = '>=',\n    visible = true,\n    properties,\n    attributes,\n  } = step;\n  const compFn = {\n    '==': (a, b) => a === b,\n    '>=': (a, b) => a >= b,\n    '<=': (a, b) => a <= b,\n  }[operator];\n  await waitForFunction(async () => {\n    const elements = await querySelectorsAll(step.selectors, frame);\n    let result = compFn(elements.length, count);\n    const elementsHandle = await frame.evaluateHandle((...elements) => {\n      return elements;\n    }, ...elements);\n    await Promise.all(elements.map((element) => element.dispose()));\n    if (result && (properties || attributes)) {\n      result = await elementsHandle.evaluate(\n        (elements, properties, attributes) => {\n          for (const element of elements) {\n            if (attributes) {\n              for (const [name, value] of Object.entries(attributes)) {\n                if (element.getAttribute(name) !== value) {\n                  return false;\n                }\n              }\n            }\n            if (properties) {\n              if (!isDeepMatch(properties, element)) {\n                return false;\n              }\n            }\n          }\n          return true;\n\n          function isDeepMatch(a, b) {\n            if (a === b) {\n              return true;\n            }\n            if ((a && !b) || (!a && b)) {\n              return false;\n            }\n            if (!(a instanceof Object) || !(b instanceof Object)) {\n              return false;\n            }\n            for (const [key, value] of Object.entries(a)) {\n              if (!isDeepMatch(value, b[key])) {\n                return false;\n              }\n            }\n            return true;\n          }\n        },\n        properties,\n        attributes\n      );\n    }\n    await elementsHandle.dispose();\n    return result === visible;\n  }, timeout);\n}\n\nasync function querySelectorsAll(selectors, frame) {\n  for (const selector of selectors) {\n    const result = await querySelectorAll(selector, frame);\n    if (result.length) {\n      return result;\n    }\n  }\n  return [];\n}\n\nasync function querySelectorAll(selector, frame) {\n  if (!Array.isArray(selector)) {\n    selector = [selector];\n  }\n  if (!selector.length) {\n    throw new Error('Empty selector provided to querySelectorAll');\n  }\n  let elements = [];\n  for (let i = 0; i < selector.length; i++) {\n    const part = selector[i];\n    if (i === 0) {\n      elements = await frame.$$(part);\n    } else {\n      const tmpElements = elements;\n      elements = [];\n      for (const el of tmpElements) {\n        elements.push(...(await el.$$(part)));\n      }\n    }\n    if (elements.length === 0) {\n      return [];\n    }\n    if (i < selector.length - 1) {\n      const tmpElements = [];\n      for (const el of elements) {\n        const newEl = (await el.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n        if (newEl) {\n          tmpElements.push(newEl);\n        }\n      }\n      elements = tmpElements;\n    }\n  }\n  return elements;\n}\n\nasync function waitForFunction(fn, timeout) {\n  let isActive = true;\n  const timeoutId = setTimeout(() => {\n    isActive = false;\n  }, timeout);\n  while (isActive) {\n    const result = await fn();\n    if (result) {\n      clearTimeout(timeoutId);\n      return;\n    }\n    await new Promise(resolve => setTimeout(resolve, 100));\n  }\n  throw new Error('Timed out');\n}\n\nasync function changeSelectElement(element, value) {\n  await element.select(value);\n  await element.evaluateHandle((e) => {\n    e.blur();\n    e.focus();\n  });\n}\n\nasync function changeElementValue(element, value) {\n  await element.focus();\n  await element.evaluate((input, value) => {\n    input.value = value;\n    input.dispatchEvent(new Event('input', { bubbles: true }));\n    input.dispatchEvent(new Event('change', { bubbles: true }));\n  }, value);\n}\n\nasync function typeIntoElement(element, value) {\n  const textToType = await element.evaluate((input, newValue) => {\n    if (\n      newValue.length <= input.value.length ||\n      !newValue.startsWith(input.value)\n    ) {\n      input.value = '';\n      return newValue;\n    }\n    const originalValue = input.value;\n    input.value = '';\n    input.value = originalValue;\n    return newValue.substring(originalValue.length);\n  }, value);\n  await element.type(textToType);\n}",ve="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",be=ve.split("").reduce(((e,t,n)=>(e.set(t,n),e)),new Map);function Ee(e){if(e<0)throw new Error("Only postive integers and zero are supported");if(e>2147483647)throw new Error("Only integers between 0 and 2147483647 are supported");const t=[];do{let n=31&e;(e>>>=5)>0&&(n|=32),t.push(ve[n])}while(0!==e);return t.join("")}function Se(e){const t=[],n=e.split("");let r=0,a=0;for(const e of n){const n=be.get(e);r|=(31&n)<<a,a+=5;32&n||(t.push(r),r=0,a=0)}return t}async function Le(e,t){var n,r,a,i,o,s,l;t||(t={});const c=null!==(n=t.extension)&&void 0!==n?n:new me,u=null!==(r=t.writer)&&void 0!==r?r:new q(null!==(a=t.indentation)&&void 0!==a?a:"  ");await(null===(i=c.beforeAllSteps)||void 0===i?void 0:i.call(c,u,e));const p=[1];for(const t of e.steps){const n=u.getSize();await(null===(o=c.beforeEachStep)||void 0===o?void 0:o.call(c,u,t,e)),await c.stringifyStep(u,t,e),await(null===(s=c.afterEachStep)||void 0===s?void 0:s.call(c,u,t,e));const r=u.getSize();p.push(n,r-n)}return await(null===(l=c.afterAllSteps)||void 0===l?void 0:l.call(c,u,e)),u.appendLine("//# recorderSourceMap="+function(e){const t=[];for(const n of e)t.push(Ee(n));return t.join("")}(p)),u.toString()}async function ke(e,t){var n,r,a,i;t||(t={});let o=t.extension;o||(o=new me),t.indentation||(t.indentation="  ");const s=null!==(n=t.writer)&&void 0!==n?n:new q(null!==(r=t.indentation)&&void 0!==r?r:"  ");return await(null===(a=o.beforeEachStep)||void 0===a?void 0:a.call(o,s,e)),await o.stringifyStep(s,e),await(null===(i=o.afterEachStep)||void 0===i?void 0:i.call(o,s,e)),s.toString()}function Fe(e){return e.trim().startsWith("//# recorderSourceMap=")}function Ae(e){const t=e.split("\n");for(let e=t.length-1;e>=0;e--){const n=t[e];if(Fe(n))return Se(n.trim().substring("//# recorderSourceMap=".length))}}function Ce(e){return e.split("\n").filter((e=>!Fe(e))).join("\n")}class $e{async beforeAllSteps(e){}async afterAllSteps(e){}async beforeEachStep(e,t){}async runStep(e,t){}async afterEachStep(e,t){}}var xe,Te,Ie;const Ne={"==":(e,t)=>e===t,">=":(e,t)=>e>=t,"<=":(e,t)=>e<=t};class Ve extends $e{constructor(e,t,n){super(),xe.add(this),this.browser=e,this.page=t,this.timeout=(null==n?void 0:n.timeout)||5e3}async runStep(e,t){const n=B(this,xe,"m",Ie).call(this,e,t),r=this.page,a=this.browser,i=await async function(e,t,n,r){if(!n.target||"main"===n.target)return t;const a=await e.waitForTarget((e=>e.url()===n.target),{timeout:r}),i=await a.page();if(!i)return null;return i.setDefaultTimeout(r),i}(a,r,e,n);let o=null;if(!i&&e.target){const t=r.frames();for(const n of t)if(n.isOOPFrame()&&n.url()===e.target){o=n;break}o||(o=await r.waitForFrame(e.target,{timeout:n}))}const s=o||i;if(!s)throw new Error("Target is not found for step: "+JSON.stringify(e));await B(this,xe,"m",Te).call(this,s);const l=await async function(e,t){let n="mainFrame"in e?e.mainFrame():e;if("frame"in t&&t.frame)for(const e of t.frame)n=n.childFrames()[e];return n}(s,e);await this.runStepInFrame(e,r,s,l,n)}async runStepInFrame(e,r,o,l,c){const u=!0;let p=null;const f=()=>{p=async function(e,t,r){const a=[];if(t.assertedEvents)for(const i of t.assertedEvents){if(i.type!==n.Navigation)throw new Error(`Event type ${i.type} is not supported`);a.push(e.waitForNavigation({timeout:r}))}await Promise.all(a)}(l,e,c)};switch(e.type){case t.DoubleClick:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);f(),await t.click({button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}}),await t.click({clickCount:2,button:e.button&&s.get(e.button),delay:e.duration,offset:{x:e.offsetX,y:e.offsetY}}),await t.dispose()}break;case t.Click:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);f(),await t.click({delay:e.duration,button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}}),await t.dispose()}break;case t.Hover:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);f(),await t.hover(),await t.dispose()}break;case t.EmulateNetworkConditions:f(),await r.emulateNetworkConditions(e);break;case t.KeyDown:f(),await r.keyboard.down(e.key),await r.waitForTimeout(100);break;case t.KeyUp:f(),await r.keyboard.up(e.key),await r.waitForTimeout(100);break;case t.Close:"close"in o&&(f(),await o.close());break;case t.Change:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);const n=await t.evaluate((e=>e.type));f(),"select-one"===n?await this.changeSelectElement(e,t):i.has(n)?await this.typeIntoElement(e,t):await this.changeElementValue(e,t),await t.dispose()}break;case t.SetViewport:"setViewport"in o&&(f(),await o.setViewport(e));break;case t.Scroll:if("selectors"in e){await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});f(),await t.evaluate(((e,t,n)=>{e.scrollTop=n,e.scrollLeft=t}),e.x||0,e.y||0),await t.dispose()}else f(),await l.evaluate(((e,t)=>{window.scroll(e,t)}),e.x||0,e.y||0);break;case t.Navigate:f(),await l.goto(e.url);break;case t.WaitForElement:try{f(),await async function(e,t,n){const{count:r=1,operator:a=">=",visible:i=!0,properties:o,attributes:s}=e,l=Ne[a];await Me((async()=>{const n=await async function(e,t){for(const n of e){const e=await Re(n,t);if(e.length)return e}return[]}(e.selectors,t);let a=l(n.length,r);const c=await t.evaluateHandle(((...e)=>e),...n);return await Promise.all(n.map((e=>e.dispose()))),a&&(o||s)&&(a=await c.evaluate(((e,t,n)=>{if(n)for(const t of e)for(const[e,r]of Object.entries(n))if(t.getAttribute(e)!==r)return!1;if(t)for(const n of e)if(!r(t,n))return!1;return!0;function r(e,t){if(e===t)return!0;if(e&&!t||!e&&t)return!1;if(!(e instanceof Object&&t instanceof Object))return!1;for(const[n,a]of Object.entries(e))if(!r(a,t[n]))return!1;return!0}}),o,s)),await c.dispose(),a===i}),n)}(e,l,c)}catch(e){throw"Timed out"===e.message?new Error("waitForElement timed out. The element(s) could not be found."):e}break;case t.WaitForExpression:f(),await l.waitForFunction(e.expression,{timeout:c});break;case t.CustomStep:break;default:a(e)}await p}async typeIntoElement(e,t){const n=await t.evaluate(((e,t)=>{if(t.length<=e.value.length||!t.startsWith(e.value))return e.value="",t;const n=e.value;return e.value="",e.value=n,t.substring(n.length)}),e.value);await t.type(n)}async changeElementValue(e,t){await t.focus(),await t.evaluate(((e,t)=>{e.value=t,e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0}))}),e.value)}async changeSelectElement(e,t){await t.select(e.value),await t.evaluateHandle((e=>{e.blur(),e.focus()}))}}xe=new WeakSet,Te=async function(e){try{await e._client().send("Emulation.setAutomationOverride",{enabled:!0})}catch{}},Ie=function(e,t){return e.timeout||(null==t?void 0:t.timeout)||this.timeout};class je extends Ve{async afterAllSteps(){await this.browser.close()}}async function Pe(e,t,n){const r=await We(e,t,{visible:!1,timeout:n});if(!r)throw new Error("The element could not be found.");await async function(e,t){await Me((async()=>await e.evaluate((e=>e.isConnected))),t)}(r,n);const a=await(async e=>await e.evaluate((e=>e instanceof SVGElement))?e:null)(r),i=a?await async function(e){return await e.evaluateHandle((e=>{var t;return null!==(t=e.ownerSVGElement)&&void 0!==t?t:e}))}(a):r;!!i&&await i.isIntersectingViewport({threshold:0})||(await async function(e){await e.evaluate((e=>{e.scrollIntoView({block:"center",inline:"center",behavior:"auto"})}))}(r),i&&await async function(e,t){await Me((async()=>await e.isIntersectingViewport({threshold:0})),t)}(i,n),await i.dispose(),i!==r&&await r.dispose())}async function We(e,t,n){for(const r of e)try{return await Oe(r,t,n)}catch(e){console.error("error in waitForSelectors",e)}throw new Error("Could not find element for selectors: "+JSON.stringify(e))}async function Oe(e,t,n){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to `waitForSelector`");let r=1===e.length,a=await t.waitForSelector(e[0],{...n,visible:r&&n.visible});for(const t of e.slice(1,e.length)){if(!a)throw new Error("Could not find element: "+e.join(">>"));const i=await a.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e));a.dispose(),r=e[e.length-1]===t,a=await i.waitForSelector(t,{...n,visible:r&&n.visible}),i.dispose()}if(!a)throw new Error("Could not find element: "+e.join(">>"));return a}async function Re(e,t){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to querySelectorAll");let n=await t.$$(e[0]);if(!n.length)return[];for(const t of e.slice(1,e.length))if(n=(await Promise.all(n.map((async e=>{const n=await e.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e)),r=await n.$$(t);return n.dispose(),e.dispose(),r})))).flat(),!n.length)return[];return n}async function Me(e,t){let n=!0;const r=setTimeout((()=>{n=!1}),t);for(;n;){if(await e())return void clearTimeout(r);await new Promise((e=>setTimeout(e,100)))}throw new Error("Timed out")}var Be,De,He,Ke,Ue,qe,Xe;async function Je(e,t,n){var r,a;await(null===(r=e.beforeEachStep)||void 0===r?void 0:r.call(e,t,n)),await e.runStep(t,n),await(null===(a=e.afterEachStep)||void 0===a?void 0:a.call(e,t,n))}class Ye{constructor(e){Be.set(this,void 0),De.set(this,void 0),He.set(this,!1),D(this,De,e,"f")}abort(){D(this,He,!0,"f")}set flow(e){D(this,Be,e,"f")}async runBeforeAllSteps(e){var t,n;await(null===(n=(t=B(this,De,"f")).beforeAllSteps)||void 0===n?void 0:n.call(t,e))}async runAfterAllSteps(e){var t,n;await(null===(n=(t=B(this,De,"f")).afterAllSteps)||void 0===n?void 0:n.call(t,e))}async runStep(e){await Je(B(this,De,"f"),e)}async run(){var e,t,n,r,a,i;if(!B(this,Be,"f"))throw new Error("Set the flow on the runner instance before calling `run`.");const o=B(this,Be,"f");if(D(this,He,!1,"f"),await(null===(t=(e=B(this,De,"f")).beforeAllSteps)||void 0===t?void 0:t.call(e,o)),B(this,He,"f"))return!1;for(const e of o.steps){if(B(this,He,"f"))return await(null===(r=(n=B(this,De,"f")).afterAllSteps)||void 0===r?void 0:r.call(n,o)),!1;await Je(B(this,De,"f"),e,o)}return await(null===(i=(a=B(this,De,"f")).afterAllSteps)||void 0===i?void 0:i.call(a,o)),!0}}async function _e(e,t){const n=e instanceof $e?e:t,r=e instanceof $e?void 0:e,a=new Ye(null!=n?n:await async function(){const{default:e}=await import("puppeteer"),t=await e.launch({headless:!0}),n=await t.newPage();return new je(t,n)}());return r&&(a.flow=r),a}Be=new WeakMap,De=new WeakMap,He=new WeakMap;class ze extends R{async beforeAllSteps(e){e.appendLine("import url from 'url';"),e.appendLine("import { createRunner } from '@puppeteer/replay';"),e.appendLine(""),e.appendLine("export async function run(extension) {").startBlock(),e.appendLine("const runner = await createRunner(extension);"),e.appendLine(""),e.appendLine("await runner.runBeforeAllSteps();"),e.appendLine("")}async afterAllSteps(e){e.appendLine(""),e.appendLine("await runner.runAfterAllSteps();").endBlock().appendLine("}"),e.appendLine(""),e.appendLine("if (process && import.meta.url === url.pathToFileURL(process.argv[1]).href) {").startBlock().appendLine("run()").endBlock().appendLine("}")}async stringifyStep(e,t){e.appendLine(`await runner.runStep(${X(t,e.getIndent())});`)}}function Ge(e){var r;return Boolean(e.type===t.Navigate||(null===(r=e.assertedEvents)||void 0===r?void 0:r.some((e=>e.type===n.Navigation))))}function Qe(e){for(const n of e.steps)if(n.type===t.SetViewport)return n.isMobile;return!1}class Ze extends me{constructor(){super(...arguments),Ke.set(this,!1)}async beforeAllSteps(e,t){e.appendLine("const fs = require('fs');"),await super.beforeAllSteps(e,t),e.appendLine("const lhApi = await import('lighthouse'); // v10.0.0 or later");e.appendLine(`const flags = ${X({screenEmulation:{disabled:!0}},e.getIndent())}`),Qe(t)?e.appendLine("const config = undefined;"):e.appendLine("const config = lhApi.desktopConfig;"),e.appendLine(`const lhFlow = await lhApi.startFlow(page, {name: ${X(t.title,e.getIndent())}, config, flags});`)}async stringifyStep(e,n,r){if(n.type===t.SetViewport)return void await super.stringifyStep(e,n,r);const a=Ge(n);a?(B(this,Ke,"f")&&(e.appendLine("await lhFlow.endTimespan();"),D(this,Ke,!1,"f")),e.appendLine("await lhFlow.startNavigation();")):B(this,Ke,"f")||(e.appendLine("await lhFlow.startTimespan();"),D(this,Ke,!0,"f")),await super.stringifyStep(e,n,r),a&&e.appendLine("await lhFlow.endNavigation();")}async afterAllSteps(e,t){B(this,Ke,"f")&&e.appendLine("await lhFlow.endTimespan();"),e.appendLine("const lhFlowReport = await lhFlow.generateReport();"),e.appendLine("fs.writeFileSync(__dirname + '/flow.report.html', lhFlowReport)"),await super.afterAllSteps(e,t)}}Ke=new WeakMap;class et extends Ve{constructor(){super(...arguments),Ue.set(this,!1),qe.set(this,!1),Xe.set(this,void 0)}async createFlowResult(){if(!B(this,Xe,"f"))throw new Error("Cannot get flow result before running the flow");return B(this,Xe,"f").createFlowResult()}async beforeAllSteps(e){var t;await(null===(t=super.beforeAllSteps)||void 0===t?void 0:t.call(this,e));const{startFlow:n,desktopConfig:r}=await import("lighthouse");let a;Qe(e)||(a=r),D(this,Xe,await n(this.page,{config:a,flags:{screenEmulation:{disabled:!0}},name:e.title}),"f")}async beforeEachStep(e,n){var r;await(null===(r=super.beforeEachStep)||void 0===r?void 0:r.call(this,e,n)),e.type!==t.SetViewport&&(Ge(e)?(B(this,Ue,"f")&&(await B(this,Xe,"f").endTimespan(),D(this,Ue,!1,"f")),await B(this,Xe,"f").startNavigation(),D(this,qe,!0,"f")):B(this,Ue,"f")||(await B(this,Xe,"f").startTimespan(),D(this,Ue,!0,"f")))}async afterEachStep(e,t){var n;B(this,qe,"f")&&(await B(this,Xe,"f").endNavigation(),D(this,qe,!1,"f")),await(null===(n=super.afterEachStep)||void 0===n?void 0:n.call(this,e,t))}async afterAllSteps(e){var t;B(this,Ue,"f")&&await B(this,Xe,"f").endTimespan(),await(null===(t=super.afterAllSteps)||void 0===t?void 0:t.call(this,e))}}Ue=new WeakMap,qe=new WeakMap,Xe=new WeakMap;export{n as AssertedEventType,M as JSONStringifyExtension,et as LighthouseRunnerExtension,Ze as LighthouseStringifyExtension,ze as PuppeteerReplayStringifyExtension,Ve as PuppeteerRunnerExtension,je as PuppeteerRunnerOwningBrowserExtension,me as PuppeteerStringifyExtension,Ye as Runner,$e as RunnerExtension,r as Schema,e as SelectorType,t as StepType,R as StringifyExtension,a as assertAllStepTypesAreHandled,_e as createRunner,z as formatAsJSLiteral,X as formatJSONAsJS,O as getSelectorType,V as maxTimeout,N as minTimeout,s as mouseButtonMap,W as parse,Ae as parseSourceMap,T as parseStep,o as pointerDeviceTypes,Le as stringify,ke as stringifyStep,Ce as stripSourceMap,i as typeableInputTypes,P as validTimeout};
